package com.yumeko.dao;

import com.yumeko.pojo.Resume;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.transaction.annotation.Transactional;


public interface ResumeDao extends PagingAndSortingRepository<Resume, Integer>, JpaSpecificationExecutor<Resume> {

    Resume findByUserNameAndPassword(String userName, String password);

    //注：jpa不支持insert语句
    @Transactional
    @Modifying(/*flushAutomatically=false*/clearAutomatically = true)
    @Query(value = "INSERT INTO tb_resume(user_name,password)  VALUES(?1,?2) ",nativeQuery = true)
    Integer InsetResume(String userName, String password);

    @Transactional
    @Modifying(/*flushAutomatically=false*/clearAutomatically = true)
    @Query(value = "UPDATE Resume SET userName=?2,password=?3 where userId=?1 ")
    Integer UpdateResume(Integer userId, String userName, String password);
}
